import json

from base_service import BaseService

# 定义OrderSettingService类，提供该服务下对应的3种方法
class OrderSettingService(BaseService):
    def __init__(self):
        super().__init__()
        self.service_name = "OrderSettingService"

    # 添加预约设置
    def add_order(self, order_setting):
        resp = self.dubbo_client.invoke(self.service_name, "add", order_setting)
        if resp == "null":
            return True
        else:
            return False

    # 按月统计预约设置信息
    def get_order_setting_by_month(self, date):
        resp = self.dubbo_client.invoke(self.service_name, "getOrderSettingByMonth", date)
        if resp == "Failed":
            return None
        else:
            return json.loads(resp)

    # 根据日期修改预约设置数量
    def edit_number_by_date(self, order_setting):
        order_setting["class"] = "com.itheima.pojo.OrderSetting"
        resp = self.dubbo_client.invoke(self.service_name, "editNumberByDate", order_setting)
        if resp == "null":
            return True
        else:
            return False
